package com.sixbro.shiro.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sixbro.shiro.common.annotation.Log;
import com.sixbro.shiro.common.utils.ApiResult;
import com.sixbro.shiro.domain.entity.SysJobLog;
import com.sixbro.shiro.service.sys.SysJobLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 定时任务日志
 * </p>
 *
 * @Author: Mr.Lu
 * @Since: 2020/6/19 15:51
 */
@Api(tags = "定时任务日志")
@RestController
@RequestMapping("/sysJobLog")
public class SysJobLogController {
    @Autowired
    private SysJobLogService sysJobLogService;

    @ApiOperation(value = "查询分页数据")
    @PostMapping("/listByPage")
    @RequiresPermissions("sysJob:list")
    public ApiResult findListByPage(@RequestBody SysJobLog sysJobLog){
        Page page = new Page(sysJobLog.getPage(), sysJobLog.getLimit());
        QueryWrapper queryWrapper = new QueryWrapper();
        //查询条件示例
        if (!StringUtils.isEmpty(sysJobLog.getJobId())) {
            queryWrapper.like("job_id", sysJobLog.getJobId());
        }
        queryWrapper.orderByDesc("create_time");
        IPage<SysJobLog> iPage = sysJobLogService.page(page, queryWrapper);
        return ApiResult.success(iPage);
    }

    @ApiOperation(value = "清空定时任务日志")
    @DeleteMapping("/delete")
    @RequiresPermissions("sysJob:delete")
    @Log(title = "清空")
    public ApiResult delete() {
        QueryWrapper queryWrapper = new QueryWrapper();
        sysJobLogService.remove(queryWrapper);
        return ApiResult.success();
    }
}
